package com.fivec.javaproject.service;

import com.alibaba.fastjson.JSONObject;
import com.fivec.javaproject.Constants;
import com.fivec.javaproject.bean.HoroscopeCommon;
import com.fivec.javaproject.net.HttpUtils;

import java.net.URLEncoder;

/**
 * @author wangyizhu
 * @version "1.8.0_131"
 * @email 2641956765@qq.com
 * @desc:
 * @Time 2021/12/20 22:27
 */
public class HoroscopeService {
    /**
     * 该方法用于获取星座运势，并将数据返回
     *
     * @param type
     * @return Address
     */
    public HoroscopeCommon getHoroscopeMessage(String constellation, String type) {
        constellation = URLEncoder.encode(constellation);
        String url = Constants.HOROSCOPE_URL
                + "?consName=" + constellation +
                "&type" + type +
                "&key=" + Constants.HOROSCOPE_KEY;
        String result = HttpUtils.get(url);
        //System.out.println(result);
        //json解析
         HoroscopeCommon horoscopeCommon = JSONObject.parseObject(result, HoroscopeCommon.class);
        //System.out.println(videoCommon.result.size());
        return horoscopeCommon;
    }
}
